package com.xbongbong.saas.service.impl;

import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.supplieruser.pojo.dto.SupplierUserDeleteBatchDTO;
import com.xbongbong.pro.supplieruser.pojo.vo.SupplierUserDeleteBatchVO;
import com.xbongbong.saas.domain.entity.SupplierUserEntity;
import com.xbongbong.saas.model.SupplierUserModel;
import com.xbongbong.saas.service.SupplierUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 供应商负责人service实现层
 * @author Jian.Wang
 * @date  2019-01-30 16:33
 * @since v1.0
 * @version v1.0
 **/
@Service("SupplierUserService")
public class SupplierUserServiceImpl implements SupplierUserService {

    private static final Logger LOG = LoggerFactory.getLogger(SupplierUserServiceImpl.class);

    @Resource
    private SupplierUserModel supplierUserModel;
    /**
     * 供应商负责人数据插入
     *
     * @param supplierUserEntity 供应商实体
     * @return Integer
     * @author Jian.Wang
     * @date 2019/1/31 10:41
     * @since v1.0
     */
    @Override
    public Integer insert(SupplierUserEntity supplierUserEntity) throws XbbException {
        return supplierUserModel.insert(supplierUserEntity);
    }

    @Override
    public SupplierUserDeleteBatchVO deleteBatch(SupplierUserDeleteBatchDTO supplierUserDeleteBatchDTO) throws XbbException {
        SupplierUserDeleteBatchVO supplierUserDeleteBatchVO = new SupplierUserDeleteBatchVO();
        try {
            List<Long> supplierIdIn = supplierUserDeleteBatchDTO.getSupplierIdIn();
            String corpid = supplierUserDeleteBatchDTO.getCorpid();
            if (Objects.nonNull(supplierIdIn) && !supplierIdIn.isEmpty()) {
                supplierUserModel.deleteBySupplierIdIn(supplierIdIn, corpid);
            }
        } catch (Exception e) {
            LOG.error("SupplierUserServiceImpl.deleteBatch出错", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
        }
        return supplierUserDeleteBatchVO;
    }
}
